package com.smile.product.web;

import com.smile.product.entity.CategoryEntity;
import com.smile.product.service.CategoryService;
import com.smile.product.vo.CateLog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;

    @GetMapping({"/","index.html"})
    public String IndexPage(Model model){
       //TODO 查出所有一级分类返回页面进行展示
        List<CategoryEntity> categoryEntities =  categoryService.getLevel1Categorys();
        model.addAttribute("catagories",categoryEntities);
        return "index";
    }




    @ResponseBody
    @GetMapping("index/catalog.json")
    public Map<String, List<CateLog2Vo>>getCatalogJson(){
        Map<String, List<CateLog2Vo>> catalogJson = categoryService.getCatalogJson();
        return catalogJson;
    }
}
